<?php
/**
 *	[TWCMS] (C)2012 TongWang Inc.
 *	$Id: theme_show.php 2 2013-04-27 07:14:17Z nanown@qq.com $
 */
class theme_show extends admin{
	public $obj;		#主题对象
	public $themeAll;	#所有主题

	function __construct() {
		parent::__construct();
		$this->main();
	}

	function main() {
		require base::load_sys_file('theme');
		if(isset($_GET['ajax'])) {
			if(in_array($_GET['ajax'], array('del'))) {
				$func = 'ajax_'.$_GET['ajax'];
				$this->$func();
			}
		}else{
			$this->getThemeAll();
			include load_tpl(__CLASS__);
		}
	}

	#删除主题
	function ajax_del() {
		$theme = strC($_POST, 'theme');
		$err = 1;
		if(!checkLaw($theme)) {
			$msg = '非法主题名';
		}elseif($theme == $this->G['theme']) {
			$msg = '不允许删除当前使用主题';
		}else{
			set_time_limit(0);
			$ret = @del_dir(TWCMS_THEME.$theme);
			$size = get_byte($ret['size']);
			if(empty($ret)) {
				$msg = '未知错误';
			}elseif($ret['fileerr'] || $ret['direrr']) {
				$msg = '删除共'.$size.'，失败'.$ret['fileerr'].'个文件 '.$ret['direrr'].'个文件夹，成功'.$ret['filenum'].'个文件 '.$ret['dirnum'].'个文件夹';
			}else{
				$msg = '删除共'.$size.'，'.$ret['filenum'].'个文件，'.$ret['dirnum'].'个文件夹';
				$err = 0;
			}
		}
		exit('{"err":"'.$err.'","msg":"'.$msg.'"}');
	}

	#读取所有主题
	function getThemeAll() {
		$this->obj = new theme();
		$this->themeAll = $this->obj->getThemeAll();
	}
}